package com.example.common.exception;

import com.example.common.enums.CommonEnums;
import com.example.common.response.SystemResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 捕获异常
     * @param e
     * @return
     */
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public SystemResponse exceptionHandler(Exception e){
        log.error("未知异常!原因是{}",e.getMessage());
        e.printStackTrace();
        return SystemResponse.response(CommonEnums.INTERNAL_SERVER_ERROR,e.getMessage());
    }


}
